<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.gqs.bookstore.vo.Catalog"%>
<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
<%@page import="com.gqs.bookstore.dao.impl.CatalogDaoImpl"%>
<%@page import="com.gqs.bookstore.dao.CatalogDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 class="page-header">
	分类维护 <small>维护书籍分类</small>
</h3>
<a href="create_catalog.jsp" class="btn btn-primary btn-large">添加书籍分类</a>

<div class="container-fluid" style="margin-top: 10px;">
<table class="table  table-bordered table-hover">
					  <caption>书籍分类表</caption>
					<thead>
						<tr>
							<th>编号</th>
							<th>名称</th>
							<th>状态</th>
							<th>创建时间</th>
							<th>更新时间</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<tr>
						<%
							CatalogDao catalogDao = new CatalogDaoImpl();
							//catalogDao.findAll()返回的是一个list，用foreach循环遍历出来
							for(Catalog catalog : catalogDao.findAll()) {//前台从数据库里全查展示出来
						%>
								<td><%=catalog.getId() %></td>
								<td><%=catalog.getName() %></td>
								<td><%=catalog.getStatus() == 0 ? "禁用" : "启用" %></td>
								<td><%=new SimpleDateFormat("yyyy-MM--dd HH:mm:ss").format(catalog.getCreateAt()) %></td>
								<td><%=new SimpleDateFormat("yyyy-MM--dd HH:mm:ss").format(catalog.getUpdateAt()) %></td>
								<td><a href="update_catalog.jsp?id=<%=catalog.getId()%>" 
									   class="btn btn-warning"><i class="icon-edit icon-white"></i>修改</a>
									<a href="do_delete_catalog.jsp?id=<%=catalog.getId() %>"
									   class="btn btn-danger"><i class="icon-trash icon-white"></i>删除</a>
									
									<!-- 修改状态和修改操作类似 -->
									<a href="do_change_status.jsp?
											id=<%=catalog.getId()%>&status=<%=1 - catalog.getStatus()%>"
											class="btn <%=catalog.getStatus()==0 ? "btn-info" : "btn-danger"%>">
											<i class="<%=catalog.getStatus() ==0 ?"icon-ok-circle" : "icon-remove-circle"%> icon-white"></i>
											<%=catalog.getStatus() ==0 ? "启用" : "禁用" %>
									</a>
									
								</td>
						</tr>
						<% 		
							}
						%>
</tbody>
</table>
</div>
</body>
</html>